# ---------------------------------------------------------------------------
# Author: Keith Hill, jachymko
# Desc:   Configures a Windows PowerShell prompt to use VS 2005
#         and .NET 2.0 compilers, libs, header files, etc.
# Date:   Dec 23, 2006
# Site:   http://www.codeplex.com/PowerShellCX
#
# Dependencies: Add-PathVariable function in GenericFunctions.ps1
#
# Usage:  In your profile place the following commands:
#  
#         . "$Env:PscxHome\Profile\Environment.ps1"
#         . "$Env:PscxHome\Profile\Environment.VisualStudio8.ps1"
# ---------------------------------------------------------------------------

. "$Env:PscxHome\Profile\GenericFunctions.ps1"

$Global:VisualStudioVersion = [Version]'8.0.50727'

# Determine the base install path
$VisualStudioKey = get-itemproperty (join-path 'HKLM:\SOFTWARE\Microsoft\VisualStudio' $VisualStudioVersion.ToString(2)) 

if (-not $VisualStudioKey) {
	$Global:VisualStudioVersion = $null
	return
}

$VSPath = split-path $VisualStudioKey.InstallDir -Parent | split-path -Parent
$VCPath = join-path $VSPath 'VC'

if (test-path $VSPath) {
	
	# Determine the configured version of the CLR
	$Global:FrameworkVersion = [Version]($VisualStudioKey.'CLR Version'.Substring(1))
	
	# Set up the base directory environment variables
	$Env:FrameworkVersion = 'v' + $FrameworkVersion.ToString(3) 
	$Env:DevEnvDir = $VisualStudioKey.InstallDir
	$Env:VSInstallDir = $VSPath
	$Env:VCInstallDir = $VCPath

	# Set the paths for the Framework and SDK directories
	$FrameworkKey = get-itemproperty HKLM:\SOFTWARE\Microsoft\.NETFramework
	$Env:FrameworkDir = $FrameworkKey.InstallRoot
	$Env:FrameworkSDKDir = $FrameworkKey.'sdkInstallRootv2.0'
		
	# Path
	Add-PathVariable 'Path' @(
		($Env:DevEnvDir),	                                  
		(join-path $VCPath 'BIN'),                          
		(join-path $VCPath 'PlatformSDK\bin'),              
		(join-path $VCPath 'VCPackages'),                   
		                                                   
		(join-path $VSPath 'Common7\Tools'),                
		(join-path $VSPath 'Common7\Tools\bin'),            
		                                                   
		(join-path $Env:FrameworkSDKDir 'bin'),           
		(join-path $Env:FrameworkDir $Env:FrameworkVersion)
	) 
	
	# Include		
	Add-PathVariable 'Include' @(
		(join-path $VCPath 'AtlMfc\Include'),
		(join-path $VCPath 'Include'),
		(join-path $VCPath 'PlatformSDK\Include'),
		(join-path $Env:FrameworkSDKDir 'Include')
	)
	 		
	# Lib
	Add-PathVariable 'Lib' @(
		(join-path $VCPath 'Lib'),
		(join-path $VCPath 'AtlMfc\Lib'),
		(join-path $VCPath 'PlatformSDK\Lib'),
		(join-path $Env:FrameworkSDKDir 'Lib')
	)
	
	# LibPath
	Add-PathVariable 'LibPath'  @(
		(join-path $VCPath 'AtlMfc\Lib'),
		(join-path $Env:FrameworkDir $Env:FrameworkVersion)
	)	
}
